import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import 'element-plus/theme-chalk/dark/css-vars.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import zhCn from "element-plus/es/locale/lang/zh-cn"
import { show_error_msg } from "./js/msg.js";

// 修改分页器默认文字
zhCn.el.pagination.total = "总共：" + `{total}` + "条"
zhCn.el.pagination.goto = "跳转至"
zhCn.el.pagination.pageSize = "{pageSize}" + "条/页"

const app = createApp(App);

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

const debounce = (fn, delay) => {
	let timer = null;

	return function () {
		let context = this;

		let args = arguments;

		clearTimeout(timer);

		timer = setTimeout(function () {
			fn.apply(context, args);
		}, delay);
	};
};

const _ResizeObserver = window.ResizeObserver;

window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
	constructor(callback) {
		callback = debounce(callback, 16);
		super(callback);
	}
};

window.addEventListener("storage", (e) => {
	if (window.location.hash == "#" || window.location.hash == "#/login") {
	  return;
	}
	show_error_msg("安全进程","已阻止对受保护内存的篡改")
	localStorage.setItem(e.key, e.oldValue);
  });

app.use(router);
app.use(ElementPlus,{ locale: zhCn });
app.mount("#app");


/*---------------------------------编译前先改我--------------------------------------*/
export const baseUrl = '/clientApi'             //调试用
// export const baseUrl = '/api'          //正式用
